#include "textitemwidget.h"
#include "ui_textitemwidget.h"
#include <QFontDialog>

TextItemWidget::TextItemWidget(int index, QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::TextItemWidget)
    , m_pIndex(index)
{
    ui->setupUi(this);
    ui->doubleSpinBox->setValue(100);
    ui->doubleSpinBox_2->setValue(100);
    ui->doubleSpinBox_3->setValue(13);
    ui->pushButton->setText(m_currentTextInfos.m_Font.family());

    m_currentTextInfos.index = m_pIndex;
    connect(ui->lineEdit, &QLineEdit::textChanged, this, &TextItemWidget::SlotUpdata);
    connect(ui->doubleSpinBox,&QDoubleSpinBox::valueChanged,this,&TextItemWidget::SlotUpdata);
    connect(ui->doubleSpinBox_2,&QDoubleSpinBox::valueChanged,this,&TextItemWidget::SlotUpdata);
    connect(ui->doubleSpinBox_3,&QDoubleSpinBox::valueChanged,this,&TextItemWidget::SlotUpdata);
    connect(ui->comboBox,&QComboBox::currentIndexChanged,this,&TextItemWidget::SlotUpdata);
}

TextItemWidget::~TextItemWidget()
{
    delete ui;
}

void TextItemWidget::SlotUpdata()
{
    m_currentTextInfos.m_text = ui->lineEdit->text();
    m_currentTextInfos.m_Point = QPointF(ui->doubleSpinBox->value(), ui->doubleSpinBox_2->value());
    m_currentTextInfos.m_direction = ui->comboBox->currentIndex();
    m_currentTextInfos.m_interval = ui->doubleSpinBox_3->value();
    emit SignalUpdata(m_currentTextInfos);
}

void TextItemWidget::on_pushButton_clicked()
{
    bool ok;
    QFont font = QFontDialog::getFont(&ok, QFont(m_currentTextInfos.m_Font.family(), m_currentTextInfos.m_Font.pointSize()), this);
    if (ok)
    {
        m_currentTextInfos.m_Font = font;
        ui->pushButton->setText(m_currentTextInfos.m_Font.family());
        SlotUpdata();
    }
}

